<template>
  <div>
    <div class="region">
      <div class="left"> <span>地区：</span></div>
      <ul>
        <li :class="{ active: RegionFlag === '' }" @click="regionchanged('')">全部</li>
        <li :class="{ active: RegionFlag === item.value }" v-for="item in RegionArr" @click="regionchanged(item.value)"
          :key="item.value">{{ item.name }}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { HospitalLevelAndRegion } from '@/api/home/type'
import { reqLevelOrRegion } from '@/api/home/index'
import { onMounted, ref } from 'vue'
let RegionArr = ref<HospitalLevelAndRegion[]>([])
//动态激活组件的高亮显示,
let RegionFlag = ref<string>('')

let emits = defineEmits<{
  (e: "onRegionChanged", data: string): void
}>()

onMounted(async () => {
  let result = await reqLevelOrRegion("BeiJin")
  if (result.code == 200) {
    RegionArr.value = result.data
  }
})
// 切换区域
let regionchanged = (value: string) => {
  RegionFlag.value = value
  emits('onRegionChanged', value)
}
</script>

<style scoped lang="scss">
.region {
  display: flex;
  color: #7f7f7f;

  .left {
    width: 60px;
  }

  ul {
    display: flex;
    flex-wrap: wrap;
    margin-left: -10px;

    li {
      margin-right: 10px;
      margin-bottom: 10px;
      cursor: pointer;

      &.active {
        color: #55a6fe;
      }
    }

    li:hover {
      color: #55a6fe;
    }
  }
}
</style>